﻿
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Runtime.Serialization;
using System.Collections.Generic;

namespace FormDesigner
{

    public class Cell
    {
        public static readonly int CellWidth = 130;
        public static readonly int CellHeight = 30;

        #region 构造函数
        public Cell()
        {

            Width = CellWidth;
            Height = CellHeight;
            isSelected = false;
            isShow = true;

            Contrls = new Dictionary<string, Point>();
        }

        public Cell(int rowindex, int columnindex)
        {
            RowIndex = rowindex;
            ColumnIndex = columnindex;

            Width = CellWidth;
            Height = CellHeight;
            isSelected = false;
            isShow = true;

            Contrls = new Dictionary<string, Point>();
        }

        /// <summary>
        /// 该单元格内的控件Name
        /// </summary>
        public Dictionary<string,Point> Contrls
        {
            get;
            set;
        }

        #endregion

        #region 坐标位置和高宽
        public int X
        {
            get;
            set;
        }

        public int Y
        {
            get;
            set;
        }

        public int Width
        {
            get;
            set;
        }

        public int Height
        {
            get;
            set;
        }
        #endregion

        public int RowIndex
        {
            get;
            set;
        }

        public int ColumnIndex
        {
            get;
            set;
        }

        //是否显示，被合并单元格后不显示
        public bool isShow
        {
            get;
            set;
        }

        public Color ShowColor
        {
            get
            {
                if (isSelected)
                    return Color.FromArgb(255, 144, 238, 144);
                else
                    return default(Color);
            }
        }

        public bool isSelected
        {
            get;
            set;
        }

        public int RowSpan
        {
            get;
            set;
        }

        public int ColumnSpan
        {
            get;
            set;
        }

        /// <summary>
        /// 根据单元格属性计算出的标识该单元格的唯一编号
        /// </summary>
        public string hashID
        {
            get
            {
                string temp = "" + X + Y + Width + Height + RowIndex + ColumnIndex + RowSpan + ColumnSpan;
                return temp;
            }

            set { }
        }

        public object Clone()
        {
            Cell c = new Cell();
            c.ColumnIndex = this.ColumnIndex;
            c.ColumnSpan = this.ColumnSpan;
            c.Height = this.Height;
            c.isSelected = this.isSelected;
            c.isShow = this.isShow;
            c.RowIndex = this.RowIndex;
            c.RowSpan = this.RowSpan;
            c.Width = this.Width;
            c.X = this.X;
            c.Y = this.Y;

            return c;
        }
    }
}
